package crmdna.federatedsecurity;

import static org.junit.Assert.assertEquals;

import java.security.NoSuchAlgorithmException;
import java.security.spec.InvalidKeySpecException;

import org.junit.Test;

import crmdna.federatedsecurity.Encryption;

public class EncryptionTest {

  @Test
  public void canLoginWithCorrectPassword() throws NoSuchAlgorithmException,
      InvalidKeySpecException {
    // password: value.add
    byte[] salt = Encryption.generateRandomSalt();

    byte[] encryptedPassword = Encryption.getEncryptedPassword("value.add", salt);

    boolean result = Encryption.authenticate("value.add", encryptedPassword, salt);
    assertEquals(true, result);
  }

  @Test
  public void cannotLoginWithInCorrectPassword() throws NoSuchAlgorithmException,
      InvalidKeySpecException {
    // password: value.add
    byte[] salt = Encryption.generateRandomSalt();

    byte[] encryptedPassword = Encryption.getEncryptedPassword("value.add", salt);

    assertEquals(false, Encryption.authenticate("value.add2", encryptedPassword, salt));
    assertEquals(false, Encryption.authenticate("Value.Add", encryptedPassword, salt));
  }
}
